package com.xinzhidi.web.netty.controller;

import com.xinzhidi.common.annotation.Log;
import com.xinzhidi.common.core.controller.BaseController;
import com.xinzhidi.common.core.domain.AjaxResult;
import com.xinzhidi.common.core.domain.R;
import com.xinzhidi.common.core.page.TableDataInfo;
import com.xinzhidi.common.enums.BusinessType;
import com.xinzhidi.common.utils.poi.ExcelUtil;
import com.xinzhidi.web.netty.entity.dto.AgreementUnitValveAddDto;
import com.xinzhidi.web.netty.entity.dto.AgreementUnitValveListDto;
import com.xinzhidi.web.netty.entity.dto.AgreementUnitValveUpdDto;
import com.xinzhidi.web.netty.entity.dto.WriteSystemInformationDto;
import com.xinzhidi.web.netty.entity.vo.AgreementUnitValveInfoVo;
import com.xinzhidi.web.netty.entity.vo.AgreementUnitValveListVo;
import com.xinzhidi.web.netty.service.AgreementUnitValveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 单元阀门协议-（实时数据）Controller
 *
 * @author cx
 * @date 2023-06-17
 */
@RestController
@Api(tags = "单元阀门协议-（实时数据）")
@RequestMapping("/agreementUnitValve")
public class AgreementUnitValveController extends BaseController {
    @Autowired
    private AgreementUnitValveService agreementUnitValveService;

    @ApiOperation("查询单元阀门协议-（实时数据）列表")
    @PreAuthorize("@ss.hasPermi('agreementUnitValve:agreementUnitValve:list')")
    @PostMapping("/listAgreementUnitValve")
    public TableDataInfo<AgreementUnitValveListVo> listAgreementUnitValve(@Validated @RequestBody AgreementUnitValveListDto dto) {
        startPagePost(dto);
        return agreementUnitValveService.selectAgreementUnitValveList(dto);
    }

    @ApiOperation("导出单元阀门协议-（实时数据）列表")
    @PreAuthorize("@ss.hasPermi('agreementUnitValve:agreementUnitValve:export')")
    @Log(title = "单元阀门协议-（实时数据）", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAgreementUnitValve")
    public void exportAgreementUnitValve(HttpServletResponse response, AgreementUnitValveListDto dto) {
        TableDataInfo<AgreementUnitValveListVo> list = agreementUnitValveService.selectAgreementUnitValveList(dto);
        ExcelUtil<AgreementUnitValveListVo> util = new ExcelUtil<AgreementUnitValveListVo>(AgreementUnitValveListVo.class);
        util.exportExcel(response, list.getRows(), "单元阀门协议-（实时数据）数据");
    }

    @ApiOperation("获取单元阀门协议-（实时数据）详细信息")
    @PreAuthorize("@ss.hasPermi('agreementUnitValve:agreementUnitValve:query')")
    @GetMapping(value = "/getAgreementUnitValveById")
    public R<AgreementUnitValveInfoVo> getAgreementUnitValveById(@RequestParam("id") Long id) {
        return R.ok(agreementUnitValveService.selectAgreementUnitValveById(id));
    }

    @ApiOperation("新增单元阀门协议-（实时数据）")
    @PreAuthorize("@ss.hasPermi('agreementUnitValve:agreementUnitValve:add')")
    @Log(title = "单元阀门协议-（实时数据）", businessType = BusinessType.INSERT)
    @PostMapping("addAgreementUnitValve")
    public AjaxResult addAgreementUnitValve(@Validated @RequestBody AgreementUnitValveAddDto dto) {
        return toAjax(agreementUnitValveService.insertAgreementUnitValve(dto));
    }

    @ApiOperation("修改单元阀门协议-（实时数据）")
    @PreAuthorize("@ss.hasPermi('agreementUnitValve:agreementUnitValve:edit')")
    @Log(title = "单元阀门协议-（实时数据）", businessType = BusinessType.UPDATE)
    @PostMapping("editAgreementUnitValve")
    public AjaxResult editAgreementUnitValve(@Validated @RequestBody AgreementUnitValveUpdDto dto) {
        return toAjax(agreementUnitValveService.updateAgreementUnitValve(dto));
    }

    @ApiOperation("删除单元阀门协议-（实时数据）")
    @PreAuthorize("@ss.hasPermi('agreementUnitValve:agreementUnitValve:remove')")
    @Log(title = "单元阀门协议-（实时数据）", businessType = BusinessType.DELETE)
    @DeleteMapping("/delAgreementUnitValve")
    public AjaxResult delAgreementUnitValve(@RequestParam Long[] ids) {
        return toAjax(agreementUnitValveService.deleteAgreementUnitValveByIds(ids));
    }

    @ApiOperation("单元阀门-【读阀门地址】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class)
    })
    @GetMapping("/readValveAddress")
    public AjaxResult readValveAddress(Long dtuId) {
        return toAjax(agreementUnitValveService.readValveAddress(dtuId));
    }

    @ApiOperation("单元阀门-【写阀门地址】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "oldAddress", value = "原地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "newAddress", value = "现地址", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/writeValveAddress")
    public AjaxResult writeValveAddress(Long dtuId, String address, String oldAddress, String newAddress) {
        return toAjax(agreementUnitValveService.writeValveAddress(dtuId, oldAddress, newAddress));
    }


    @ApiOperation("单元阀门-【读 系 统 信 息】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/readSystemInformation")
    public AjaxResult valveOperatingMode(Long dtuId, String address) {
        return toAjax(agreementUnitValveService.readSystemInformation(dtuId, address));
    }

    @ApiOperation("单元阀门-【写 系 统 信 息】指令下发")
    @PostMapping("/writeSystemInformation")
    public AjaxResult writeSystemInformation(@Validated @RequestBody WriteSystemInformationDto dto) {
        return toAjax(agreementUnitValveService.writeSystemInformation(dto));
    }

    @ApiOperation("单元阀门-【阀门控制-设置阀门开度】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "valveOpen", value = "阀门开度（十进制）", dataType = "int", dataTypeClass = Integer.class)
    })
    @GetMapping("/setValveOpen")
    public AjaxResult setValveOpen(Long dtuId, String address, Integer valveOpen) {
        return toAjax(agreementUnitValveService.setValveOpen(dtuId, address, valveOpen));
    }

    @ApiOperation("单元阀门-【阀门控制-顺时针旋转】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "degrees", value = "顺时针旋转度数（十进制）", dataType = "int", dataTypeClass = Integer.class)
    })
    @GetMapping("/clockwiseRotation")
    public AjaxResult clockwiseRotation(Long dtuId, String address, Integer degrees) {
        return toAjax(agreementUnitValveService.clockwiseRotation(dtuId, address, degrees));
    }

    @ApiOperation("单元阀门-【阀门控制-逆时针旋转】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "degrees", value = "逆时针旋转度数（十进制）", dataType = "int", dataTypeClass = Integer.class)
    })
    @GetMapping("/CounterclockwiseRotation")
    public AjaxResult CounterclockwiseRotation(Long dtuId, String address, Integer degrees) {
        return toAjax(agreementUnitValveService.CounterclockwiseRotation(dtuId, address, degrees));
    }

    @ApiOperation("单元阀门-【停止阀门】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/stopValve")
    public AjaxResult stopValve(Long dtuId, String address) {
        return toAjax(agreementUnitValveService.stopValve(dtuId, address));
    }

}
